_helo = _this select 0;
_callsign = _this select 1;
_class = _this select 2;
_spwn = _this select 3;
_vehinit = _this select 4;
_array = _this;
// hint format ["%1",_class];

//////////////////////////////// Start of Map section //////////////////////////////////
//if(_helo getVariable "RUM_inFlight")exitwith{hint "Helo in flight";};

RUM_ASclick = false;

openMap [true,true];
for [{_n=1},{_n<=6},{_n=_n+1}] do {
	_mkrname = "";
	_type = "";
	_hint = "";
	switch (_n) do {
		case 1: {
			_mkrname = format ["%1target",_helo];
			_type = "mil_pickup";
			_hint = "Select Pick-Up LZ";
		};
		case 2: {
			_mkrname = format ["%1ingress",_helo];
			_type = "mil_start";
			_hint = "Select Pick-Up LZ Ingress Point";
		};
		case 3: {
			_mkrname = format ["%1egress",_helo];
			_type = "mil_end";
			_hint = "Select Pick-Up LZ Egress Point";
		};
		case 4: {
			_mkrname = format ["%1target2",_helo];
			_type = "mil_pickup";
			_hint = "Select Drop-Off LZ";
		};
		case 5: {
			_mkrname = format ["%1ingress2",_helo];
			_type = "mil_start";
			_hint = "Select Drop-Off LZ Ingress Point";
		};
		case 6: {
			_mkrname = format ["%1egress2",_helo];
			_type = "mil_end";
			_hint = "Select Drop-Off LZ Egress Point";
		};
		default {
			hint "shit";	
		};
	};
	_asloc = createMarkerLocal [_mkrname, [0,0,0]];
	_asloc setMarkerShapeLocal "ICON";
	_mkrname setMarkerTypeLocal _type;
	_stgtar = format ["'%1' setMarkerPosLocal _pos;RUM_ASclick = true",_mkrname];
	onMapSingleClick _stgtar;
	titleText [_hint, "PLAIN DOWN"];
	waitUntil {RUM_ASclick};
	if((_n == 2) or (_n == 3)) then {
		_mkrname2 = format ["%1target",_helo];
		_mkrname setMarkerDirLocal ((getMarkerPos _mkrname2 select 0)-(getMarkerPos _mkrname select 0)) atan2 ((getMarkerPos _mkrname2 select 1)-(getMarkerPos _mkrname select 1));
	};
	if((_n == 5) or (_n == 6)) then {
		_mkrname2 = format ["%1target2",_helo];
		_mkrname setMarkerDirLocal ((getMarkerPos _mkrname2 select 0)-(getMarkerPos _mkrname select 0)) atan2 ((getMarkerPos _mkrname2 select 1)-(getMarkerPos _mkrname select 1));
	};
	onMapSingleClick "";
	RUM_ASclick = false;
};

titleFadeOut 0;
sleep 1;
openMap [false,false];

//////////////////////////////////// End of Map section //////////////////////////////////
//////////////////////////////////// Start of Helo Setup //////////////////////////////////
_varOM = false;

_spwndir = getdir _spwn;

_helosave = _helo;
_helo = createVehicle [_class, getPos _spwn, [], 0, "FLY"];
_helo setVehicleVarName _helosave;
_helo setpos [(getpos _spwn select 0),(getpos _spwn select 1),(getpos _spwn select 2)+RUM_THEL_flyHeight];
//hint format["this is the init: %1",_init];
_helo setdir _spwndir;
_helo setVariable ["RUM_inFlight", true, true];
_helo setVehicleInit format ["%1;", _vehinit];
processInitCommands;
// create a global array to control init options
RUM_THel_InitControl = _array;
publicVariable "RUM_THel_InitControl";


_grp = createGroup side player;
_pilot1 = _grp createUnit [RUM_THEL_Pilot, getpos _spwn, [], 0, "FORM"];
_pilot1 moveinDriver _helo;
_pilot2 moveincargo _helo;
_helo lockDriver true;

_grp2 = createGroup side player;
_crew = [];
_cfg=configFile >> "CfgVehicles" >> typeof _helo >> "turrets";
//changed to _n=0 since this will put the other gunner in...otherwise it spawns in with only one gunner
	for [{_n=0},{_n<count _cfg},{_n=_n+1}] do {
		_gunner = _grp2 createUnit [RUM_THEL_Pilot, getpos _spwn, [], 0, "FORM"];
		_helo lockTurret [[_n], false];
		_gunner moveinTurret [_helo,[_n]];
		_helo lockTurret [[_n], true];
		if!(_gunner in crew _helo)then{deleteVehicle _gunner};
		_crew = _crew + [_gunner];
	};
_grp2 setCombatMode "RED";
_grp2 setBehaviour "COMBAT";
//////////////////////////////////// End of Helo Setup //////////////////////////////////
_varOM = false;
sleep 2;

if(_helo iskindof "Plane")then{_helo FlyInHeight RUM_THEL_flyHeightPLN}else{_helo FlyInHeight RUM_THEL_flyHeight};
["shuffle",[player,_pilot1,_callsign]] execVM (RUM_PATH+"Transport\radiodialogs.sqf");
sleep 16;

//	
for [{_n=1},{_n<=2},{_n=_n+1}] do {
	_mkrname = "";
	switch (_n) do {
		case 1: {
			_mkrname = format ["%1ingress",_helo];
			[_mkrname,_grp] call RUM_THel_movewaypoint;
			_crewCount = _helo getVariable ["_crewVariable",(count crew _helo)];
			_helo setVariable ["_crewVariable",_crewCount,true];
			// debug
			player globalchat format ["start crew %1",_crewCount];
		};
		case 2: {
			_mkrname = format ["%1target",_helo];
			_lz = [_mkrname,_grp] call RUM_THel_landwaypoint;
			if (_class == "MV22") then {
				sleep 45;
			};
			call RUM_THel_VehicleOptions;
		};
	};
};

if(RUM_THEL_smokeLZ)then{
	_helo spawn {
		_mkrname = format ["%1target",_this];
		_asloc = getMarkerPos _mkrname;
		waitUntil{((((getPos _this select 0) - (_asloc select 0))^2+((getPos _this select 1) - (_asloc select 1))^2)^0.5) < 1500};
		_smoke = createVehicle ["SmokeShell", _asloc, [], 0, "NONE"];
	};
};

	_cont = format ["%1",_helo];

	RUM_THel_land = "";
	waitUntil {(!alive _helo) or (RUM_THel_land == _cont)};

	_helo land "get in";
	_stg = format ["%1 : Move On!",_callsign];
	_stg2 = format ["%1 : Abort, RTB!",_callsign];
	
if (alive _helo) then {
	RUM_THel_actionid = player addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign]];
	RUM_THel_actionid2 = _helo addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign],1,false,true,"","_this in _target"];
	// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
};
sleep 3;

_helo setVariable ["RUM_THel_continue",false,true];
waitUntil {(!alive _helo) or (_helo getVariable "RUM_THel_continue")};
if(RUM_THEL_invisibleH)then{deleteVehicle _lz};

for [{_n=1},{_n<=3},{_n=_n+1}] do {
	_mkrname = "";	
	switch (_n) do {	
		case 1: {			
			_mkrname = format ["%1egress",_helo];
			[_mkrname,_grp] call RUM_THel_moveWPTakeoff;
			sleep 10;
			[_mkrname,_grp] call RUM_THel_movewaypoint;
		};
		case 2: {
			_mkrname = format ["%1ingress2",_helo];
			[_mkrname,_grp] call RUM_THel_movewaypoint;
		};
		case 3: {
			_mkrname = format ["%1target2",_helo];
			_lz = [_mkrname,_grp] call RUM_THel_landwaypoint;
			if (_class == "MV22") then {
				sleep 45;
			};
			call RUM_THel_VehicleOptions;
		};
	};
};

if(RUM_THel_Special == "Para Drop")then{
	_helo FlyInHeight RUM_THEL_flyHeightPara;
};
if(RUM_THel_Special == "HALO Jump")then{
	_helo FlyInHeight RUM_THEL_flyHeightHALO;
};

if(RUM_THel_Special == "Para Drop" or RUM_THel_Special == "HALO Jump")then{
	_mkrname = format ["%1egress",_helo];
	[_mkrname,_grp] call RUM_THel_movewaypoint;
};
	
_cont = format ["%1",_helo];
RUM_THel_land = "";
waitUntil {(!alive _helo) or (RUM_THel_land == _cont)};

switch (RUM_THel_Special) do {
		_stg2 = format ["%1 : Abort, RTB!",_callsign];
	case "Normal":{
		_helo land "get out";
		_stg = format ["%1 : Move On!",_callsign];
	
		if (alive _helo) then {
			RUM_THel_actionid = player addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign]];
			RUM_THel_actionid2 = _helo addAction [_stg, (RUM_PATH+"Transport\om.sqf"),[_helo,_callsign],1,false,true,"","_this in _target"];
		};
	};
	case "Combat Landing":{
		_crew = crew _helo;

		_cargo = ((_crew - units _grp) - units _grp2);
		player globalchat format ["Number of Cargo Slots in Use: %1", _cargo];
		[_helo, _cargo] execVM (RUM_PATH+"Transport\RUM_CBLand.sqf");
		// [_cargo,_helo,false] execVM (RUM_PATH+"Transport\combat_insertion.sqf");
		// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
	};
	case "Fast Rope":{
		// Norrin Fastrope addon required
		// hint "NORRIN";
		_helo FlyInHeight 35;
		[_helo, 0, 60, ""] execVM (RUM_PATH+"Transport\fastrope\NORRN_fastRope_init.sqf");
		// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
	};
	case "Para Drop":{
		_crew = crew _helo;
		_cargo = ((_crew - units _grp) - units _grp2);
		{unassignvehicle _x;_x action ["EJECT",_helo];sleep 0.5;} forEach _cargo;
		_helo spawn {sleep 1;_this setVariable ["RUM_THel_continue",true,true]};
		// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
	};
	case "HALO Jump":{
		_crew = crew _plane;
		_cargo = ((_crew - units _grp) - units _grp2);
		_plane spawn {sleep 1;_this setVariable ["RUM_THel_continue",true,true]};
		cutText ["This is the Drop Zone!","PLAIN",2];
		// RUM_THel_actionid3 = player addAction [_stg2, (RUM_PATH+"Transport\abort.sqf"),[_arry]];
	};	
	default{hint "shit"};
};

_helo setVariable ["RUM_THel_continue",false,true];
waitUntil {(!alive _helo) or (_helo getVariable "RUM_THel_continue")};
if(RUM_THEL_invisibleH)then{deleteVehicle _lz};
if(_helo iskindof "Plane")then{_helo FlyInHeight RUM_THEL_flyHeightPLN}else{_helo FlyInHeight RUM_THEL_flyHeight};

for [{_n=1},{_n<=2},{_n=_n+1}] do {
	_mkrname = "";	
	switch (_n) do {	
		case 1: {			
			_mkrname = format ["%1egress2",_helo];
			[_mkrname,_grp] call RUM_THel_movewaypoint;
		};
		case 2: {
			[_mkrname,_grp,_spwn] call RUM_THel_Spawn;
		};
	};
};

waitUntil{(!alive _helo) or (((((getPos _helo select 0) - (getpos _spwn select 0))^2+((getPos _helo select 1) - (getpos _spwn select 1))^2)^0.5) <= 300)};

sleep 1;
_crew = crew _helo;
deleteVehicle _helo;
{deleteVehicle _x} forEach _crew;

_mkrname1 = format ["%1ingress",_helo];
_mkrname2 = format ["%1target",_helo];
_mkrname3 = format ["%1egress",_helo];

deletemarkerLocal _mkrname1;
deletemarkerLocal _mkrname2;
deletemarkerLocal _mkrname3;

_mkrname4 = format ["%1ingress2",_helo];
_mkrname5 = format ["%1target2",_helo];
_mkrname6 = format ["%1egress2",_helo];

deletemarkerLocal _mkrname4;
deletemarkerLocal _mkrname5;
deletemarkerLocal _mkrname6;

_varOM = false;
player sidechat format["%1 has left the AO",_helo];

RUM_THel_InitControl = "";
publicVariable "RUM_THel_InitControl";

//_helo setVariable ["RUM_inFlight", false, true];

if(true)exitwith{};
